using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Reflection;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

using System.IO;
using TVC.Layout;

namespace TVC.Modules.Com
{
    /// <summary>
    /// Summary description for CustomWindowPanelControl.
    /// </summary>

    [Serializable()]
    public class SNS : ModuleParent, IHostedApplication
    {
        private TabControl tabControl1;
        private TabPage tbList;
        private TabPage tbDetail;
        private Label label3;
        private TextBox txtLOOKUP;
        private Label label2;
        private TextBox txtDESCRIPTION;
        private TextBox txtCODE;
        private Label label1;
        private Label label8;
        private Label label7;
        private TextBox txtLEDGER;
        private DataGridView dgvList;
        private TextBox txtMODE;
        private Label label4;
        private NumericUpDown nudNEXT_NUMBER;
        private DateTimePicker dpCURRENTDATE;
        private Label label6;
        private TextBox txtFORMAT;
        private Label label5;
        private DataGridViewTextBoxColumn colCODE;
        private DataGridViewTextBoxColumn colLOOKUP;
        private DataGridViewTextBoxColumn colDESCRIPTION;
        private BindingSource bisSNS;
        private IContainer components;
        private CheckBox chkResetMonth;
        GridLayout layout = null;
        private ContextMenu ctmGrid;
        private MenuItem menuItem1;
        private MenuItem mnuSaveLayout;
        private MenuItem mnuResetLayout;
        private MenuItem mnuShowFilter;
        private string strAction;
        public SNS()
        {
            // This call is required by the WebGUI Form Designer.
            InitializeComponent();
            _strType = "SNS";
            _dgvList = dgvList;
            _tabControl = tabControl1;
        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.tabControl1 = new Gizmox.WebGUI.Forms.TabControl();
            this.tbList = new Gizmox.WebGUI.Forms.TabPage();
            this.dgvList = new Gizmox.WebGUI.Forms.DataGridView();
            this.colCODE = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.colLOOKUP = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.colDESCRIPTION = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.bisSNS = new Gizmox.WebGUI.Forms.BindingSource(this.components);
            this.tbDetail = new Gizmox.WebGUI.Forms.TabPage();
            this.chkResetMonth = new Gizmox.WebGUI.Forms.CheckBox();
            this.dpCURRENTDATE = new Gizmox.WebGUI.Forms.DateTimePicker();
            this.label6 = new Gizmox.WebGUI.Forms.Label();
            this.txtFORMAT = new Gizmox.WebGUI.Forms.TextBox();
            this.label5 = new Gizmox.WebGUI.Forms.Label();
            this.label4 = new Gizmox.WebGUI.Forms.Label();
            this.nudNEXT_NUMBER = new Gizmox.WebGUI.Forms.NumericUpDown();
            this.txtMODE = new Gizmox.WebGUI.Forms.TextBox();
            this.label3 = new Gizmox.WebGUI.Forms.Label();
            this.label8 = new Gizmox.WebGUI.Forms.Label();
            this.txtLOOKUP = new Gizmox.WebGUI.Forms.TextBox();
            this.label7 = new Gizmox.WebGUI.Forms.Label();
            this.label2 = new Gizmox.WebGUI.Forms.Label();
            this.txtDESCRIPTION = new Gizmox.WebGUI.Forms.TextBox();
            this.txtCODE = new Gizmox.WebGUI.Forms.TextBox();
            this.txtLEDGER = new Gizmox.WebGUI.Forms.TextBox();
            this.label1 = new Gizmox.WebGUI.Forms.Label();
            this.ctmGrid = new Gizmox.WebGUI.Forms.ContextMenu();
            this.menuItem1 = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuSaveLayout = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuResetLayout = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuShowFilter = new Gizmox.WebGUI.Forms.MenuItem();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tbList.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisSNS)).BeginInit();
            this.tbDetail.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.nudNEXT_NUMBER)).BeginInit();
            this.SuspendLayout();
            // 
            // errProvider
            // 
            this.errProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // warnProvider
            // 
            this.warnProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // tabControl1
            // 
            this.tabControl1.Alignment = Gizmox.WebGUI.Forms.TabAlignment.Bottom;
            this.tabControl1.Appearance = Gizmox.WebGUI.Forms.TabAppearance.Workspace;
            this.tabControl1.Controls.Add(this.tbList);
            this.tabControl1.Controls.Add(this.tbDetail);
            this.tabControl1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(3, 3);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(601, 442);
            this.tabControl1.TabIndex = 0;
            // 
            // tbList
            // 
            this.tbList.Controls.Add(this.dgvList);
            this.tbList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbList.Location = new System.Drawing.Point(4, 22);
            this.tbList.Name = "tbList";
            this.tbList.Size = new System.Drawing.Size(593, 416);
            this.tbList.TabIndex = 0;
            this.tbList.Text = "List";
            // 
            // dgvList
            // 
            this.dgvList.AllowDrag = false;
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.BackgroundColor = System.Drawing.Color.White;
            this.dgvList.ColumnHeadersHeightSizeMode = Gizmox.WebGUI.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvList.Columns.AddRange(new Gizmox.WebGUI.Forms.DataGridViewColumn[] {
            this.colCODE,
            this.colLOOKUP,
            this.colDESCRIPTION});
            this.dgvList.ContextMenu = this.ctmGrid;
            this.dgvList.DataSource = this.bisSNS;
            this.dgvList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.dgvList.Location = new System.Drawing.Point(0, 0);
            this.dgvList.Name = "dgvList";
            this.dgvList.RowHeadersWidth = 25;
            this.dgvList.RowTemplate.DefaultCellStyle.FormatProvider = new System.Globalization.CultureInfo("en-US");
            this.dgvList.ShowFilterRow = true;
            this.dgvList.Size = new System.Drawing.Size(593, 416);
            this.dgvList.TabIndex = 0;
            // 
            // colCODE
            // 
            this.colCODE.DataPropertyName = "CODE";
            this.colCODE.HeaderText = "Code";
            this.colCODE.Name = "colCODE";
            // 
            // colLOOKUP
            // 
            this.colLOOKUP.DataPropertyName = "LOOKUP";
            this.colLOOKUP.HeaderText = "Look Up";
            this.colLOOKUP.Name = "colLOOKUP";
            // 
            // colDESCRIPTION
            // 
            this.colDESCRIPTION.AutoSizeMode = Gizmox.WebGUI.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.colDESCRIPTION.DataPropertyName = "DESCRIPTION";
            this.colDESCRIPTION.HeaderText = "Description";
            this.colDESCRIPTION.Name = "colDESCRIPTION";
            // 
            // bisSNS
            // 
            this.bisSNS.DataSource = typeof(DTO.SNSInfo);
            // 
            // tbDetail
            // 
            this.tbDetail.Controls.Add(this.chkResetMonth);
            this.tbDetail.Controls.Add(this.dpCURRENTDATE);
            this.tbDetail.Controls.Add(this.label6);
            this.tbDetail.Controls.Add(this.txtFORMAT);
            this.tbDetail.Controls.Add(this.label5);
            this.tbDetail.Controls.Add(this.label4);
            this.tbDetail.Controls.Add(this.nudNEXT_NUMBER);
            this.tbDetail.Controls.Add(this.txtMODE);
            this.tbDetail.Controls.Add(this.label3);
            this.tbDetail.Controls.Add(this.label8);
            this.tbDetail.Controls.Add(this.txtLOOKUP);
            this.tbDetail.Controls.Add(this.label7);
            this.tbDetail.Controls.Add(this.label2);
            this.tbDetail.Controls.Add(this.txtDESCRIPTION);
            this.tbDetail.Controls.Add(this.txtCODE);
            this.tbDetail.Controls.Add(this.txtLEDGER);
            this.tbDetail.Controls.Add(this.label1);
            this.tbDetail.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbDetail.Location = new System.Drawing.Point(0, 0);
            this.tbDetail.Name = "tbDetail";
            this.tbDetail.Size = new System.Drawing.Size(593, 416);
            this.tbDetail.TabIndex = 1;
            this.tbDetail.Text = "Detail";
            // 
            // chkResetMonth
            // 
            this.chkResetMonth.AutoSize = true;
            this.chkResetMonth.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.chkResetMonth.Location = new System.Drawing.Point(259, 172);
            this.chkResetMonth.Name = "chkResetMonth";
            this.chkResetMonth.Size = new System.Drawing.Size(87, 17);
            this.chkResetMonth.TabIndex = 8;
            this.chkResetMonth.Text = "Reset Month";
            // 
            // dpCURRENTDATE
            // 
            this.dpCURRENTDATE.CalendarFirstDayOfWeek = Gizmox.WebGUI.Forms.Day.Default;
            this.dpCURRENTDATE.CustomFormat = "dd/MM/yyyy";
            this.dpCURRENTDATE.Format = Gizmox.WebGUI.Forms.DateTimePickerFormat.Custom;
            this.dpCURRENTDATE.Location = new System.Drawing.Point(86, 129);
            this.dpCURRENTDATE.Name = "dpCURRENTDATE";
            this.dpCURRENTDATE.Size = new System.Drawing.Size(100, 21);
            this.dpCURRENTDATE.TabIndex = 4;
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(16, 132);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(46, 13);
            this.label6.TabIndex = 0;
            this.label6.Text = "Current Date";
            // 
            // txtFORMAT
            // 
            this.txtFORMAT.AllowDrag = false;
            this.txtFORMAT.Location = new System.Drawing.Point(86, 221);
            this.txtFORMAT.Multiline = true;
            this.txtFORMAT.Name = "txtFORMAT";
            this.txtFORMAT.Size = new System.Drawing.Size(436, 48);
            this.txtFORMAT.TabIndex = 7;
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(16, 224);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(35, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Format";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(16, 199);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(46, 13);
            this.label4.TabIndex = 0;
            this.label4.Text = "Next number";
            // 
            // nudNEXT_NUMBER
            // 
            this.nudNEXT_NUMBER.AutoValidate = Gizmox.WebGUI.Forms.AutoValidate.EnablePreventFocusChange;
            this.nudNEXT_NUMBER.CurrentValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.nudNEXT_NUMBER.CurrentValueChanged = false;
            this.nudNEXT_NUMBER.Location = new System.Drawing.Point(86, 197);
            this.nudNEXT_NUMBER.Maximum = new decimal(new int[] {
            1000000,
            0,
            0,
            0});
            this.nudNEXT_NUMBER.Name = "nudNEXT_NUMBER";
            this.nudNEXT_NUMBER.Size = new System.Drawing.Size(100, 20);
            this.nudNEXT_NUMBER.TabIndex = 6;
            this.nudNEXT_NUMBER.TextAlign = Gizmox.WebGUI.Forms.HorizontalAlignment.Left;
            // 
            // txtMODE
            // 
            this.txtMODE.AllowDrag = false;
            this.txtMODE.Location = new System.Drawing.Point(86, 170);
            this.txtMODE.MaxLength = 15;
            this.txtMODE.Name = "txtMODE";
            this.txtMODE.Size = new System.Drawing.Size(100, 20);
            this.txtMODE.TabIndex = 5;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(16, 41);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(35, 13);
            this.label3.TabIndex = 0;
            this.label3.Text = "Look Up";
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(16, 106);
            this.label8.Name = "label5";
            this.label8.Size = new System.Drawing.Size(46, 13);
            this.label8.TabIndex = 0;
            this.label8.Text = "Ledger";
            // 
            // txtLOOKUP
            // 
            this.txtLOOKUP.AllowDrag = false;
            this.txtLOOKUP.Location = new System.Drawing.Point(86, 38);
            this.txtLOOKUP.MaxLength = 15;
            this.txtLOOKUP.Name = "txtLOOKUP";
            this.txtLOOKUP.Size = new System.Drawing.Size(100, 20);
            this.txtLOOKUP.TabIndex = 1;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(16, 173);
            this.label7.Name = "label6";
            this.label7.Size = new System.Drawing.Size(46, 13);
            this.label7.TabIndex = 0;
            this.label7.Text = "Mode";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 67);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Description";
            // 
            // txtDESCRIPTION
            // 
            this.txtDESCRIPTION.AllowDrag = false;
            this.txtDESCRIPTION.Location = new System.Drawing.Point(86, 64);
            this.txtDESCRIPTION.Name = "txtDESCRIPTION";
            this.txtDESCRIPTION.Size = new System.Drawing.Size(436, 20);
            this.txtDESCRIPTION.TabIndex = 2;
            // 
            // txtCODE
            // 
            this.txtCODE.AllowDrag = false;
            this.txtCODE.Location = new System.Drawing.Point(86, 12);
            this.txtCODE.MaxLength = 15;
            this.txtCODE.Name = "txtCODE";
            this.txtCODE.Size = new System.Drawing.Size(100, 20);
            this.txtCODE.TabIndex = 0;
            // 
            // txtLEDGER
            // 
            this.txtLEDGER.AllowDrag = false;
            this.txtLEDGER.Location = new System.Drawing.Point(86, 103);
            this.txtLEDGER.Name = "txtLEDGER";
            this.txtLEDGER.Size = new System.Drawing.Size(100, 20);
            this.txtLEDGER.TabIndex = 3;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Code";
            // 
            // ctmGrid
            // 
            this.ctmGrid.MenuItems.AddRange(new Gizmox.WebGUI.Forms.MenuItem[] {
            this.menuItem1,
            this.mnuShowFilter});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new Gizmox.WebGUI.Forms.MenuItem[] {
            this.mnuSaveLayout,
            this.mnuResetLayout});
            this.menuItem1.Text = "Layout";
            // 
            // mnuSaveLayout
            // 
            this.mnuSaveLayout.Index = 0;
            this.mnuSaveLayout.Tag = "SAVE";
            this.mnuSaveLayout.Text = "Save Layout";
            // 
            // mnuResetLayout
            // 
            this.mnuResetLayout.Index = 1;
            this.mnuResetLayout.Tag = "RESET";
            this.mnuResetLayout.Text = "Reset Layout";
            // 
            // mnuShowFilter
            // 
            this.mnuShowFilter.Index = 1;
            this.mnuShowFilter.Tag = "FILTER";
            this.mnuShowFilter.Text = "Filter Records";
            // 
            // SNS
            // 
            this.BackColor = System.Drawing.Color.White;
            this.Controls.Add(this.tabControl1);
            this.DockPadding.All = 3;
            this.Location = new System.Drawing.Point(0, -10);
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(607, 448);
            this.Load += new System.EventHandler(this.SNS_Load);
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tbList.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisSNS)).EndInit();
            this.tbDetail.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.nudNEXT_NUMBER)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        int idAllowEditLanguage = 1;
        int idAddNew = 1;
        int idEdit = 1;
        int idDelete = 1;
        int idclsTransferIn = 1;
        int idclsTransferOut = 1;
        int idPrint = 1;





        protected override void AllowEditLanguage()
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    x.DoubleClick += Control_DoubleClick;
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    x.DoubleClick += Control_DoubleClick;
                    foreach (Control y in x.Controls)
                    {
                        y.DoubleClick += Control_DoubleClick;
                    }
                }
            }

        }

        protected override void LoadLanguage(string language)
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            clsConfigurarion.GetLabel(this.ToString(), y, language);
                    }
                }
            }

            if (this.Parent is HeaderedPanel)
            {
                HeaderedPanel pln = this.Parent as HeaderedPanel;
                _title = clsConfigurarion.GetLabel(this.ToString(), "", null, language);
            }
        }
        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Add New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idAddNew) && IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S"));
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Copy", new IconResourceHandle("Copy.png"), "O"));
            if (IsPermis(idDelete))
                objElements.Add(new HostedToolBarButton("Delete", new IconResourceHandle("Delete.png"), "X"));
            

            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idclsTransferIn))
                objElements.Add(new HostedToolBarButton("Import", new IconResourceHandle("Down.png"), "TI"));
            if (IsPermis(idPrint)) objElements.Add(new HostedToolBarButton("To XML", "To XML", new IconResourceHandle("Up.png"), "TO"));
            if (IsPermis(idPrint)) objElements.Add(new HostedToolBarButton("To Excel", "To Excel", new IconResourceHandle("Excel.png"), "EXCEL"));

            objElements.Add(new HostedToolBarSeperator());
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }


        #region IHostedApplication Members

        public void InitializeApplication()
        {
        }

      
        public void SetObject(object obj)
        {
        }


        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                strAction = (string)objButton.Tag;

                BUS.SNSControl ctr = new BUS.SNSControl();
                switch (strAction)
                {
                    case "C":
                        AddNew(txtCODE);
                        break;
                    case "A":
                        editRecord(txtCODE);
                        break;
                    case "S":
                        saveRecord(txtCODE);
                        break;
                    case "O":
                        copy(txtCODE);
                        break;
                    case "X":
                        delete(txtCODE);
                        break;
                    case "TI": //trans in
                        importData();
                        break;
                    case "TO": //Tran out
                        export2Xml();
                        break;
                    case "EXCEL": //Tran out
                        export2Excel();
                        break;
                    case "R":
                        reloadList();
                        break;
                    case "P":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.SNSInfo info = new DTO.SNSInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            DataTable dt = DTO.SNSInfo.ToDataTable();
                            dt.Rows.Add(info.ToDataRow(dt));
                            DataSet ds = new DataSet();
                            ds.Tables.Add(dt);
                            MainForm main = GetMainForm();
                            if (main != null)
                                main.PrintDataSet(ds, _strType);
                        }
                        break;
                }
               
                if (sErr == "")
                    ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }
        #region .::| Override Functions |::.
        protected override ModuleParent.ErrorStatus validateForm(ref string sErr)
        {
            ErrorStatus result = ErrorStatus.SUCCESS;
            sErr = "";

            if (txtCODE.Text.Trim() == "")
            {
                sErr = "Could not save blank, please check!";
                errProvider.SetError(txtCODE, sErr);
                strAction = _processStatus;
                sErr += "\n";
            }
            else errProvider.SetError(txtCODE, "");


            if (sErr != "") result = ErrorStatus.ERROR;
            return result;
        }
        protected override bool checkExists()
        {
            return new BUS.SNSControl().IsExist(GetMainForm().DB, txtCODE.Text);
        }
        protected override string addRecord(bool isDraft = false)
        {
            string sErr = "";
            DTO.SNSInfo info = GetData();
            BUS.SNSControl ctr = new BUS.SNSControl();
            ctr.Add(info,ref sErr);
            
            return sErr;
        }
        protected override string updateRecord(bool isDraft = false)
        {
            string sErr = "";
            DTO.SNSInfo info = GetData();
            BUS.SNSControl ctr = new BUS.SNSControl();
            sErr=ctr.Update(info);
            
            return sErr;
        }
        protected override string delRecord()
        {
            string sErr = "";
            BUS.SNSControl ctr = new BUS.SNSControl();
            sErr= ctr.Delete(GetMainForm().DB, txtCODE.Text);
            return sErr;
        }
       
        protected override void refreshForm(string val)
        {
            txtCODE.Text = val;
            txtDESCRIPTION.Text = val;
            txtFORMAT.Text = val;
            txtLEDGER.Text = val;
            txtMODE.Text = val;
            txtLOOKUP.Text = val;

            nudNEXT_NUMBER.Value = 0;
        }
        protected override void enableForm(bool val)
        {
            txtCODE.Enabled = val;
            txtDESCRIPTION.Enabled = val;
            txtFORMAT.Enabled = val;
            txtLEDGER.Enabled = val;
            txtMODE.Enabled = val;
            txtLOOKUP.Enabled = val;
            nudNEXT_NUMBER.Enabled = val;
        }
        protected override void reloadList()
        {
            GetMainForm().LoadDataTable(_strType);
            bisSNS.DataSource = GetMainForm().GetTable(_strType);
        }
        protected override void loadRecord(object o)
        {
            if (o is DataRowView)
            {
                DTO.SNSInfo inf = new DTO.SNSInfo((DataRowView)o);
                SetData(inf);
            }
        }

        #endregion

        private DTO.SNSInfo GetData()
        {
            return new DTO.SNSInfo(GetMainForm().DB
            , txtLOOKUP.Text
                , GetMainForm().PODInfo.USER_ID
                , GetMainForm().PODInfo.USER_ID
                , BUS.CommonControl.ConvertDateToInt(DateTime.Now)
                , BUS.CommonControl.ConvertDateToInt(DateTime.Now)
                , txtCODE.Text
                , txtDESCRIPTION.Text
                , txtLEDGER.Text
                , txtMODE.Text
                , nudNEXT_NUMBER.Value.ToString()
                , txtFORMAT.Text
                , BUS.CommonControl.ConvertDateToInt(dpCURRENTDATE.Value).ToString()
            ,chkResetMonth.Checked == true? 1 : 0);

        }

        private void SetData(DTO.SNSInfo info)
        {
            txtCODE.Text = info.CODE;
            txtDESCRIPTION.Text = info.DESCRIPTION;
            txtFORMAT.Text = info.FORMAT;
            txtLEDGER.Text = info.LEDGER;
            txtMODE.Text = info.MODE;
            txtLOOKUP.Text = info.LOOKUP;
            try
            {
                nudNEXT_NUMBER.Value = Convert.ToDecimal(info.NEXT_NUMBER);
                chkResetMonth.Checked = info.ResetMonth == 0 ? false : true;
            }
            catch { }
        }

        #endregion

        private void SNS_Load(object sender, EventArgs e)
        {

            enableForm(false);
            refreshForm("");
           


            if (idAllowEditLanguage >= GetMainForm().Permission.Length || GetMainForm().Permission[idAllowEditLanguage] == 'Y')
                AllowEditLanguage();

        }

    }
}
